var _contextPath;

function getContextPath() {
	if ("" == _contextPath || 'undefined' == _contextPath) {
		_contextPath = $("#contextPath").val();
	}
	return _contextPath;
}

/**
 * 卡销户下一步
 */
function submit() {
	if (!$("#form").form('validate')){
		return false;
	}
	var cardNum = $('#cardNum').val();
	if (!$("#cardfrom").form('validate')){
		return false;
	}
	if (cardNum == '' || typeof (cardNum) == 'undefined') {
		cardNum.uppShow('未输入卡号!');
		return;
	}
	var pwd = $('#pwd').val();
//	alert(cardNum+","+pwd+'================');
	$.ajax({
		type : 'POST',
		url :  contextPath + 'iccard/rechargecard/canceledCardInfo',
		data : {
			'cardNum' : cardNum,
			'pwd' : pwd
		},
		dataType : 'json',
		success : function(root) {
			if (root.opResult == '0') {
				window.location.href = contextPath + "iccard/recharge/rechargecard_cancelation.jsp?cardNum="+cardNum;
			} else {
				top.uppShow(root.msgDesc);
			}
		},
		error : function(data) {
			uppAjaxError(data);
		}
	});
	
}
var st = true;
var _cardNum ;
var _status ;
var _type;
$.extend($.fn.validatebox.defaults.rules, {
	checkCardNum : {
		validator : function(value, param) {
			if(!/^[0-9]\d{18}$/.test(value,param)){
                $.fn.validatebox.defaults.rules.checkCardNum.message = '卡号为19位纯数字.';
                return false;
            }
			if(value != _cardNum){
            	st = true;
            }
            if(st){
            	var data = {cardNum:value};
         		 $.ajax({ 
         			 url : contextPath+'iccard/rechargecard/loadInfoByCardNum',
         			 data : data,
         			 async : false,
         			 type : "POST",
         			 success : function(root){
         				 var amount = root.amountTotal;
         				 // 0：新卡
         				 // 1：复用卡
         				 var type = root.type;
         				 /*
         				  * 0:入库 1:出库 2:激活 3:冻结 4:销户
         				  */
         				 var status = root.status;
         				 var pwdresult = root.pwdresult;
         				 var pwd1result = root.pwd1result;
         				 _type = type;
         				 _status = status;
         				 //alert("cardNum:"+cardNum+",rechargeMoney:"+rechargeMoney+",status:"+status+",type:"+type+",amout:"+amount);
         			 }
         		 })
         		 _cardNum = value;
         		 st = false;
             }
             if(_status != 2 ){
            	 $.fn.validatebox.defaults.rules.checkCardNum.message = '不能对状态为入库、出库、冻结和已销户的卡进行销户';
                 return false;
             }else{
            	 return true;
             }
		},
		message : '卡号为19位纯数字.'
	},
	checkPwd : {
		validator : function(value,param) {
			if(!/^[0-9]\d{5}$/.test(value,param)){
                $.fn.validatebox.defaults.rules.checkCardNum.message = '密码为6位纯数字.';
                return false;
            }else{
            	return true;
            }
		},
		message : '密码为6位纯数字.'
	}
});

